home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / JimmDemos / DemoSource / oscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  6.6 KB  |  283 lines

  1. /* oscan.c -- overscan demo
  2.  * Copyright (c) 1988, I and I Computing and Commodore-Amiga, Inc.
  3.  *
  4.  * Executables based on this information may be used in software
  5.  * for Commodore Amiga computers.  All other rights reserved.
  6.  *
  7.  * This information is provided "as is"; no warranties are made.
  8.  * All use is at your own risk, and no liability or responsibility is assumed.
  9.  */
  10.  
  11. #include "sysall.h"
  12. #include "oscan.h"
  13.  
  14. #include "getargs.h"
  15.  
  16. struct Screen *getScreen();
  17. struct Window *getWindow();
  18. struct BitMap *getHugeBitMap();
  19.  
  20. extern struct IntuitionBase    *IntuitionBase;
  21.  
  22. struct BitMap    *bmap = NULL;
  23. struct Screen    *screen = NULL;
  24. struct Window    *window = NULL;
  25. struct View        *view;
  26.  
  27. SHORT            viewdx;        /* original values found in view Dx/yOffset    */
  28. SHORT            viewdy;
  29.  
  30. /* gadget stuff from oscreen.c    */
  31. extern UBYTE    oribuff0[];
  32. extern UBYTE    oribuff1[];
  33. extern struct StringInfo    mysi[];
  34. #define OSCAN_VIEWX        (mysi[0].LongInt)
  35. #define OSCAN_VIEWY        (mysi[1].LongInt)
  36.  
  37. /* cheat: won't work beyond V1.3    */
  38. #define MAXXMOUSE    (700)
  39. #define MAXYMOUSE    (470)
  40. SHORT orig_maxx;
  41. SHORT orig_maxy;
  42.  
  43. /* idcmp flags */
  44. ULONG    iflags = 
  45.         GADGETUP| INTUITICKS| MENUPICK| MENUVERIFY|
  46.         INACTIVEWINDOW| NEWPREFS| RAWKEY;
  47.  
  48. /* window flags */
  49. ULONG    flags =
  50.         ACTIVATE | NOCAREREFRESH | SIMPLE_REFRESH | BACKDROP | BORDERLESS ;
  51.  
  52. /* some extreme values for View.Dx/DyOffset    */
  53. #define    REASONABLE_DX    (96)
  54. #define    REASONABLE_DY    (21)
  55.  
  56. /* tricky stuff */
  57. #define NO_TRICK        (0)    /* means standard screen, standard position */
  58. #define VIEWSHIFT_TRICK    (2)    /* shift the view, but don't poke Intuition    */
  59. #define CHEAT_TRICK        (1)    /* perform hack that won't be supported in future */
  60.  
  61. /* current and previous view states */
  62. int        trick    =        NO_TRICK;    
  63. int        lasttrick =        NO_TRICK;
  64.  
  65. int        numplanes = 1;
  66.  
  67. struct Arg myargs[] = {
  68.     {'p', ARG_TINT, &numplanes, "number of bitplanes [1-4]"},
  69. };
  70.  
  71. main(argc, argv)
  72. char    **argv;
  73. {
  74.     struct IntuiMessage    *imsg;
  75.  
  76.     if ( getargs( argv, myargs, NUMARGS( myargs ), NULL) < 0 ) cleanup( NULL );
  77.  
  78.     /* --- open libraries ---                                */
  79.     if (!OpenI( 33 )) cleanup( "no intuition\n");
  80.     if (!OpenGfx( 33 )) cleanup("no graphics\n");
  81.  
  82.     view = ViewAddress();        /* for later tricks            */
  83.     viewdx = view->DxOffset;
  84.     viewdy = view->DyOffset;
  85.  
  86.     /* initialize string gadgets     */
  87.     mysi[0].LongInt = REASONABLE_DX;
  88.     mysi[1].LongInt = REASONABLE_DY;
  89.  
  90.     sprintf( mysi[0].Buffer, "%ld", mysi[0].LongInt);
  91.     sprintf( mysi[1].Buffer, "%ld", mysi[1].LongInt);
  92.     sprintf( oribuff0, "orig. %d (0x%x)", viewdx, viewdx);
  93.     sprintf( oribuff1, "orig. %d (0x%x)", viewdy, viewdy);
  94.  
  95.     /* --- allocate huge bitmap ---                            */
  96.     if ( ! ( bmap = getHugeBitMap( numplanes ) ) ) cleanup( "no bitmap\n" );
  97.  
  98.     /* --- open "standard" screen/window on huge bitmap ---    */
  99.     if (!( screen = getScreen( bmap ) ) ) cleanup( "no screen\n" );
  100.  
  101.     if (!( window = getWindow( screen ) ) ) cleanup( "no window\n" );
  102.     drawHugeBitMap( &screen->RastPort );
  103.  
  104.     /* --- top-level input processing ---                    */
  105.     for (;;)
  106.     {
  107.         WaitPort( window->UserPort );
  108.         imsg = (struct IntuiMessage *) GetMsg( window->UserPort );
  109.  
  110.         switch ( imsg->Class )
  111.         {
  112.         case GADGETUP:
  113.             /* i guess i don't really care after all */
  114.             break;
  115.  
  116.         case MENUPICK:
  117.             /* using a single, simple menu    */
  118.             switch ( ITEMNUM( imsg->Code ) )
  119.             {
  120.             case 0:
  121.                 dotrick( VIEWSHIFT_TRICK );        /* view shift    */
  122.                 break;
  123.  
  124.             case 1:
  125.                 dotrick( CHEAT_TRICK );        /* cheat, too.    */
  126.                 break;
  127.  
  128.             case 2:
  129.                 printf("menupick untrick\n");
  130.                 untrick();
  131.                 break;
  132.  
  133.             case 3:        /* exit */
  134.                 ReplyMsg( imsg );
  135.                 cleanup( "all done\n" );
  136.  
  137.             default:                /* return to tricky mode    */
  138.                 dotrick( lasttrick );
  139.             }
  140.             break;
  141.  
  142.         case INTUITICKS:
  143.             /* thanks to David Joiner (talin) for this (un-)trick    */
  144.             if ( (trick != NO_TRICK) && (IntuitionBase->FirstScreen != screen) )
  145.             {
  146.                 printf("tick untrick trick = %d\n", trick);
  147.                 untrick();
  148.             }
  149.             break;
  150.  
  151.         case MENUVERIFY:
  152.             printf("menuverify untrick\n");
  153.             untrick();
  154.             break;
  155.  
  156.         case INACTIVEWINDOW:
  157.             printf("inactive untrick\n");
  158.             untrick();
  159.             break;
  160.  
  161.         case NEWPREFS:
  162.             /* be careful: untrick() causes another NEWPREFS message!    */
  163.             if ( trick != NO_TRICK )
  164.             {
  165.                 printf("newprefs untrick\n");
  166.                 untrick();    /* haven't tested this too much    */
  167.             }
  168.             break;
  169.  
  170.         default:
  171.             break;
  172.         }
  173.  
  174.         ReplyMsg( imsg );    /* must follow menuverify */
  175.     }
  176. }
  177.  
  178. dotrick( tr )
  179. {
  180.     if ( trick != NO_TRICK )
  181.     {
  182.         printf("dotrick untrick\n");
  183.         untrick();
  184.     }
  185.  
  186.     if ( IntuitionBase->FirstScreen != screen ) return;
  187.  
  188.     switch ( tr )
  189.     {
  190.     case CHEAT_TRICK:        /* cheap unsupportable hacks    */
  191.         /*
  192.          * save and change values of data fields which will
  193.          * not be used under V1.4
  194.          */
  195.         orig_maxx = IntuitionBase->MaxXMouse;
  196.         orig_maxy = IntuitionBase->MaxYMouse;
  197.  
  198.         IntuitionBase->MaxXMouse =            MAXXMOUSE;
  199.         IntuitionBase->MaxYMouse =            MAXYMOUSE;
  200.         IntuitionBase->MaxDisplayWidth =    MAXXMOUSE;
  201.         IntuitionBase->MaxDisplayRow =        MAXYMOUSE;
  202.         IntuitionBase->MaxDisplayHeight =    IntuitionBase->MaxDisplayRow + 1;
  203.  
  204.         /* fall through    */
  205.  
  206.     case VIEWSHIFT_TRICK:        /* shifted view trick    */
  207.         view->DxOffset = OSCAN_VIEWX;
  208.         view->DyOffset = OSCAN_VIEWY;
  209.         RemakeDisplay();
  210.         break;
  211.  
  212.     default:
  213.         printf("bad dotrick untrick\n");
  214.         untrick();
  215.         tr = NO_TRICK;
  216.     }
  217.  
  218.     /* ClearPointer will get Intuition to ChangeSprite(),
  219.      * and keep the pointer sync'd with display position.
  220.      *
  221.      * In a real application, I would use the address of my
  222.      * window within the large screen, and would try to insure
  223.      * that my window was active when I do this trick.
  224.      * It's not a big problem if this operation doesn't succeed:
  225.      * it corrects itself as soon as the user moves the mouse.
  226.      *
  227.      * This Forbid() stuff is because I'm not sure that I can
  228.      * pass a NULL to ClearPointer()
  229.      */
  230.     Forbid();
  231.     if (IntuitionBase->ActiveWindow) ClearPointer( IntuitionBase->ActiveWindow );
  232.     Permit();
  233.  
  234.     lasttrick = trick = tr;
  235. }
  236.  
  237. untrick()
  238. {
  239.     LONG    dummy;
  240.  
  241.     switch ( trick )
  242.     {
  243.     case CHEAT_TRICK:
  244.         IntuitionBase->MaxXMouse =            orig_maxx;
  245.         IntuitionBase->MaxYMouse =            orig_maxy;
  246.         IntuitionBase->MaxDisplayWidth =    orig_maxx;
  247.         IntuitionBase->MaxDisplayRow =        orig_maxy;
  248.         IntuitionBase->MaxDisplayHeight =    IntuitionBase->MaxDisplayRow + 1;
  249.  
  250.         /* fall through    */
  251.  
  252.     case NO_TRICK:
  253.     case VIEWSHIFT_TRICK:
  254. #if 0
  255.         view->DxOffset = viewdx;
  256.         view->DyOffset = viewdy;
  257. #else
  258.         /* this method intereracts less with other tricksters */
  259.         GetPrefs( &dummy, (LONG) sizeof dummy );
  260.         SetPrefs( &dummy, (LONG) sizeof dummy );
  261. #endif
  262.         RemakeDisplay();            /* fix up everybody    */
  263.         break;
  264.     }
  265.     trick = NO_TRICK;
  266. }
  267.  
  268.  
  269. cleanup( string )
  270. char    *string;
  271. {
  272.     if ( string ) printf("%s", string);
  273.  
  274.     if ( window ) CloseWindow( window );
  275.     if ( screen ) CloseScreen( screen );
  276.     if ( bmap )    freeHugeBitMap( bmap );
  277.  
  278.     CloseI();
  279.     CloseGfx();
  280.  
  281.     exit ( string? 1: 0 );        /* should I have said !!string ?    */
  282. }
  283.